const dbpool=require("../config/dbpoolconfig")

const bodyController={

    //获取所有用户信息
    getCurrentUser(req,resp){
        let pageCount=6;//每页展示几条信息
        let currentPage=req.query.currentPage;//当前页
        console.log("--------------------")
        console.log(currentPage);
        /*
        * 0,3    -----  1
        * 3, 3 ------ 2
        * 6,3 -------3
        *
        * (currentPage-1)*pageCount    ,   pageCount
        *
        * */

        dbpool.connect("select * from user limit ?,?",[(currentPage-1)*pageCount,pageCount ],(err,data)=>{
            if(!err){
                if(data.length>0){
                    resp.send(data);
                }
            }
        })
    },

    //获取总共有多少页
    getPageTotal(req,resp){
        //总页码=数据总条数/每页展示多少条
        let pageCount=6; //每页展示多少条

        dbpool.connect("select count(*) as totalcount from user",[],(err,data)=>{
            if(!err){
                // console.log(data[0].totalcount);
                let result=Math.ceil(data[0].totalcount/pageCount)
                console.log(result)
                result=String(result);
                resp.send(result)
            }
        })

    }
}

module.exports=bodyController;